package org.example.sb_api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.example.sb_api.annotation.RequireLogin;
import org.example.sb_api.common.Result;
import org.example.sb_api.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "车辆管理")
@RestController
@RequestMapping("/api/recharge/vehicle")
@RequireLogin
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    @ApiOperation("获取车辆列表")
    @GetMapping("/list")
    public Result getVehicleList(HttpServletRequest request) {
        // 从token中获取userId
        Long userId = (Long) request.getAttribute("userId");
        return vehicleService.getVehicleList(userId);
    }

    @ApiOperation("获取车辆详情")
    @GetMapping("/detail/{id}")
    public Result getVehicleDetail(
            @ApiParam(value = "车辆ID", required = true)
            @PathVariable Long id,
            HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        return vehicleService.getVehicleDetail(id);
    }

    @ApiOperation("设置默认车辆")
    @PutMapping("/setDefault/{id}")
    public Result setDefaultVehicle(
            @ApiParam(value = "车辆ID", required = true)
            @PathVariable Long id,
            HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        return vehicleService.setDefaultVehicle(id);
    }
} 